package com.ITArmy.controller.admin;

import com.ITArmy.beans.Exchange;
import com.ITArmy.common.ServerResponse;
import com.ITArmy.controller.base.BaseController;
import com.ITArmy.service.ExchangeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(value = "后台汇率接口层次", tags = "后台汇率接口层次Controller层")
@Controller
@RequestMapping("/admin/Exchange")
public class AdminExchangeController extends BaseController {

    @RequestMapping("/list")
    @ApiOperation(value = "显示汇率信息",
            httpMethod = "POST", response = ServerResponse.class)
    public String list(Model model) {
        ServerResponse exchangeServerResponse=exchangeService.findExchange();
        model.addAttribute("exchangeList",exchangeServerResponse.getData());
        return "exchange";
    }

    @RequestMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改信息时显示原始信息",
            httpMethod = "POST", response = ServerResponse.class)
    public ServerResponse edit(Integer id) {
        return exchangeService.findExchangeById(id);
    }

    @RequestMapping("/update")
    @ResponseBody
    @ApiOperation(value = "修改汇率信息，",
            httpMethod = "POST", response = ServerResponse.class)
    public ServerResponse update(Exchange exchange) {
        return exchangeService.updateExchange(exchange);
    }
}
